package com.wlc.service.impl;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wlc.mapper.UserMapper;
import com.wlc.service.UserService;
import com.wlc.vo.Student;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.lang.reflect.Field;
import java.util.List;

/**
 * @author 王立朝
 * @date 2023/11/3
 * @description:
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, Student> implements UserService {


	@Override
	public boolean updateStudent() {
		UpdateWrapper<Student> updateWrapper = new UpdateWrapper<>();
		updateWrapper.set("name","张三222");
		updateWrapper.eq("name","张三111");

		boolean update = this.update(updateWrapper);
		return update;
	}

	@Override
	public List<Student> getUsers(Student student) {

		QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("name", StringUtils.hasLength(student.getName()) ?  student.getName() : "");
		List<Student> list = this.list(queryWrapper);
		System.out.println(list);
		return list;
	}

	@Override
	public List<Student> getUsers2(String name) {
		QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("name",name);
		List<Student> list = this.list(queryWrapper);
		return list;
	}

	@Override
	public int getNumber() {
		System.out.println( "进入了getNumber（）方法");
		return 102;
	}

	/**
	 * 测试反射获取对象属性
	 * @param args
	 */
	public static void main(String[] args) {
		Class<Student> clazz = Student.class;

		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			if (field.isAnnotationPresent(TableField.class)) {
				TableField annotation = field.getAnnotation(TableField.class);
				String columnName = annotation.value();
				System.out.println("Field: " + field.getName() + ", Column: " + columnName);
			}
		}
	}
}
